package com.huazi.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huazi.commonutils.CommentResult;
import com.huazi.educms.entity.CrmBanner;
import com.huazi.educms.service.CrmBannerService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author huazi
 * @since 2021-03-25
 */
@RestController
@CrossOrigin
@RequestMapping("/educms/bannerAdmin")
public class BannerAdminController {
    @Autowired
    CrmBannerService crmBannerService;
    //添加一个banner
    @ApiModelProperty("添加banner")
    @PostMapping("addBannerAdmin")
    public CommentResult addBannerAdmin(@RequestBody CrmBanner banner){
        boolean save = crmBannerService.addBannerAdmin(banner);
        if(save) return CommentResult.getOK();
        return CommentResult.getError();
    }
    //删除一个banner
    @ApiModelProperty("删除banner")
    @DeleteMapping("deleteBannerAdmin/{id}")
    public CommentResult deleteBannerAdmin(@PathVariable String id){
        crmBannerService.deleteBannerAdmin(id);
        return CommentResult.getOK();
    }
    //查询所有banner
    @ApiModelProperty("获取所有banner")
    @GetMapping("getBannerAdmins")
    public CommentResult getBannerAdmins(){
        List<CrmBanner> list = crmBannerService.getBannerAdmins();
        return CommentResult.getOK().data("bannerList",list);
    }
    //根据id查询banner
    @ApiModelProperty("根据id获取banner")
    @GetMapping("getBannerAdminOne/{id}")
    public CommentResult getBannerAdminOne(@PathVariable String id){
        CrmBanner banner = crmBannerService.getBannerAdminOne(id);
        return CommentResult.getOK().data("banner",banner);
    }
    //修改一个banner
    @ApiModelProperty("修改banner")
    @PostMapping("modBannerAdmin")
    public CommentResult modBannerAdmin(@RequestBody CrmBanner banner){
        crmBannerService.modBannerAdmin(banner);
        return CommentResult.getOK();
    }
    //分页查询banner
    @ApiModelProperty("分页查询信息")
    @GetMapping("getBannerAdminPage/{page}/{limit}")
    public CommentResult getBannerAdminOne(@PathVariable int page, @PathVariable int limit){
        //创建分页插件
        Page<CrmBanner> pages=new Page<>(page,limit);
        //调用分页查询
        crmBannerService.page(pages,null);

        return CommentResult.getOK().data("pages",pages);
    }

}

